package com.horoscope.astrology.zodiac.signs.free.utils

import android.animation.ObjectAnimator
import android.view.animation.Animation
import android.view.animation.LinearInterpolator
import android.view.animation.RotateAnimation
import android.widget.ImageView

object MyAnimationUtils {
    fun loadingAnimation(): Animation {
        val rotateAnimation = RotateAnimation(
            0f, 360f
            , Animation.RELATIVE_TO_SELF, 0.5f
            , Animation.RELATIVE_TO_SELF, 0.5f
        )
        rotateAnimation.duration = 500
        rotateAnimation.fillAfter = true
        rotateAnimation.repeatMode = Animation.RESTART
        rotateAnimation.interpolator = LinearInterpolator()
        rotateAnimation.repeatCount = -1
        return rotateAnimation
    }

    /**
     * 增加旋转动画
     */
    var animRotate: ObjectAnimator? = null

    fun startRotation(view: ImageView) {
        animRotate = ObjectAnimator.ofFloat(view, "rotation", 0f, 360f)
        animRotate!!.repeatMode = ObjectAnimator.RESTART
        animRotate!!.interpolator = LinearInterpolator()
        animRotate!!.repeatCount = -1
        animRotate!!.duration = 1000L
        animRotate!!.start()
    }

    fun pauseRotation() {
        animRotate!!.pause()
    }

    fun stopRotation() {
        animRotate!!.cancel()
    }

    fun resumeRotation() {
        animRotate!!.resume()
    }


}